<?php

class Client extends AppModel
{
	var $name = 'Client';
	var $hasMany = 'Survey';
	var $displayField = 'first_name';
	
	var $validate = array(
							'username' => array(
												'notempty' => array(
																	'rule' => array('minLength', 1),
																	'required' => true,
																	'allowEmpty' => false,
																	'message' => 'User name cannot be empty'
																	),
												'unique' => array(
																	'rule' => array('checkUnique', 'username'),
																	'message' => 'User name is taken.  Try another'
																)
												),
							'password' => array(
												'notempty' => array(
																	'rule' => array('minLength', 1),
																	'required' => true,
																	'allowEmpty' => false,
																	'message' => 'Password cannot be empty.'
																	)
												),
							'email' => array(
											'rule' => 'email',
											'required' => true,
											'allowEmpty' => false,
											'message' => 'Please enter a valid email'
											)
						);

	function checkUnique($data, $fieldName)
	{
		$valid = false;
		
		if (isset($fieldName) && $this->hasField($fieldName))
		{
			$valid = $this->isUnique(array($fieldName => $data));
		}
		
		return $valid;
	}
}

?>
